import { gql } from '@apollo/client';
import { withApollo, graphql } from '@apollo/client/react/hoc';
import { compose } from 'recompose';
import viewstateHoc from '@kuiper-components/viewstate-hoc';

export default compose(
	withApollo,
	graphql(
		gql`
			query($id: MongoID!, $assetId: MongoID!) {
				TaskOne(
					filter: {
						status: completed
						OR: [{ refId: $id }, { refId: $assetId }]
					}
					sort: ENDTIME_DESC
				) {
					_id
					endTime
				}
				JobOne(filter: { _id: $id }) {
					_id
					vulResult {
						_id
						result {
							warningCount
							warnings {
								level
								isResolved
								ignoredTime
								_id
							}
						}
					}
					securityEventResult {
						_id
						result {
							warningCount
							warnings {
								level
								isResolved
								ignoredTime
								_id
							}
						}
					}
					contentResult {
						_id
						result {
							warningCount
							warnings {
								level
								isResolved
								ignoredTime
								_id
							}
						}
					}
					sslResult {
						_id
						result {
							warningCount
							warnings {
								level
								isResolved
								ignoredTime
								_id
							}
						}
					}
					httpResult {
						_id
						result {
							warningCount
						}
					}
					pingResult {
						_id
						result {
							warningCount
						}
					}
				}
			}
		`,
		{
			skip: ({ jobId }) => !jobId,
			options({ jobId, assetId }) {
				return {
					variables: { assetId, id: jobId },
				};
			},
		}
	),
	viewstateHoc({ size: 'small' })
);
